﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dbPoll_Application.ViewModels.PollViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript"> 
     
    onload = function(){
        <% 
            int j = 0;
            foreach (var poll in Model.polls)
            {
        %>
            var geocoder;
            geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(<%=poll.latitude%>, <%=poll.longitude%>);
            
           geocoder.geocode({ 'latLng': latlng }, function(results, status) {
                        document.getElementById('location<%=poll.pollID%>').innerHTML = results[0].formatted_address;
                    });                   
            <%
                j++;
                }
            %>
            
        }   
    </script> 
    <div class="pageHeadingContainer"><h2 class="pageHeading">Respond</h2></div>
    <div id="contentContainer">
    <p>Select a poll from the list.</p>
    <table class="questions">
    <tr>
    <th class="pollNameCol">Name</th>
    <th class="pollFinishCol">Finish Time</th>
    <th class="pollLatCol">Location</th>
    </tr>
    <% foreach (var poll in Model.polls)
       { %>
    <tr>
    <% if (poll.pollClose < DateTime.Now)
       { %>
       <td class="pollNameCol"><%= poll.name %></td>
    <% } 
       else { %>
    <td class="pollNameCol"><%= Html.ActionLink(poll.name, "ResponseQuestions", "Respond", new { pollID = poll.pollID}, null) %></td>
    <% } %>
    <td class="pollFinishCol"><%= poll.pollClose.ToString("dd/MM/yyyy hh:mm tt") %></td>
    <td class="pollLatCol" id="location<%=poll.pollID%>"></td>
    </tr>
    <% } %>
    </table>
    </div>

</asp:Content>
